package com.zhugang.week01;

/**
 * @program algorithms
 * @description: drink3
 * @author: chanzhugang
 * @create: 2022/05/21 16:06
 */
public class Drink3 {

    public static void main(String[] args) {
        Drink3 drink3 = new Drink3();
        int count = drink3.drink(7);
        System.out.println(count);


        int count2 = drink3.numWaterBottles(9, 3);
        System.out.println(count2);
    }
    /**
     * x瓶啤酒， 3个空瓶能换一个，7个瓶盖也能换一个，问总共能喝多少瓶啤酒
     *
     * @param x
     * @return
     */
    public int drink(int x) {
        int count = x;
        int k1 = x;
        int k2 = x;
        while (k1 >= 3 || k2 >= 7) {
            while (k1 >= 3) {
                int changes = k1 / 3;
                count += changes;
                k1 %= 3;
                k1 += changes;
                k2 += changes;
            }
            while (k2 >= 7) {
                int changes = k2 / 7;
                count += changes;
                k2 %= 7;
                k2 += changes;
                k1 += changes;
            }
        }
        return count;
    }

    /**
     * 1518.换酒问题
     * @param numBottles
     * @param numExchange
     * @return
     */
    public int numWaterBottles(int numBottles, int numExchange) {
        int count = numBottles;
        int k = numBottles;
        while (k >= numExchange) {
            int changes = k / numExchange;
            count += changes;
            k %= numExchange;
            k += changes;
        }
        return count;
    }
}